﻿using System.Collections.Generic;
using System.Linq;
using yiCommerce.Core.Domain.ShoppingCarts;
using yiCommerce.Core.Helper;

namespace yiCommerce.Service.Products
{
    public class ProductAttributeParser:IProductAttributeParser
    {
        public bool AreProductAttributesEqual(string attributesXml, string selectedAttributes)
        {

            var productVariantAttributeValueFromShoppingCart = JsonHelper.ToObject<List<ProductVariantAttributeValueXml>>(attributesXml);
            var productVariantAttributeValueFromClient = JsonHelper.ToObject<List<ProductVariantAttributeValueXml>>(selectedAttributes);

            var c1 = string.Join(",",productVariantAttributeValueFromClient.Select(c=>c.AttributeValueId).OrderBy(t=>t).ToList());
            var c2 = string.Join(",", productVariantAttributeValueFromShoppingCart.Select(c => c.AttributeValueId).OrderBy(t => t).ToList());

            return c1 == c2;
        }
    }
}